/*
 * Copyright (c) 2015. For Intelligent Group.
 */

require.config({
    baseUrl: "js",
    paths: {
        "jquery": "libs/jquery-2.0.2.min",
        "domReady": "requirejs/domReady",
        "jquery-touch": "plugin/jquery-touch",
        "bootstrap": "bootstrap/",
        "notification": "notification",
        "smartwidgets": "smartwidgets",
        "easy-pie-chart": "plugin/easy-pie-chart",
        "sparkline": "plugin/sparkline",
        "jquery-validate": "plugin/jquery-validate",
        "jquery-form": "plugin/jquery-form",
        "datetimepicker": "plugin/datetimepicker",
        "masked-input": "plugin/masked-input",
        "select2": "plugin/select2",
        "bootstrap-slider": "plugin/bootstrap-slider",
        "msie-fix": "plugin/msie-fix",
        "fastclick": "plugin/fastclick",
        "i18n": "plugin/i18n",
        "jquery-cookie": "libs",
        "sockjs": "plugin/sockjs/sockjs.min",
        "stomp": "plugin/stomp",
        "head": "core/head",
        "model": "core/model",
        "business": "core/business",
        "common": "core/common",
        "appLocalStorage": "core/common/appLocalStorage",
        "appConst": "core/common/appConstant",
        "dateUtils": "core/common/dateUtils",
        "stringUtils": "core/common/stringUtils",
        "appMessageBox": "core/common/appMessageBox",
        // "datatables":"plugin/datatables",
        // "datatable-responsive":"plugin/datatable-responsive",
        "jeditable": "plugin/jquery-jeditable",
        "bootstrap-wizard": "plugin/bootstrap-wizard",
        "datetimepicker": "plugin/datetimepicker",
        'jquery.dataTables.min': "plugin/datatables/jquery.dataTables.min",
        'dataTables.colVis.min': "plugin/datatables/dataTables.colVis.min",
        'dataTables.tableTools.min': "plugin/datatables/dataTables.tableTools.min",
        'dataTables.bootstrap.min': "plugin/datatables/dataTables.bootstrap.min",
        'dataTables.responsive.min': "plugin/datatable-responsive/datatables.responsive.min",
        'x-editable': 'plugin/x-editable',
        'typeahead': 'plugin/typeahead',
        'moment.min': "plugin/x-editable/moment.min"
    },
    shim: {
        'app.config': ['jquery'],
        'jquery.i18n.properties': ['jquery'],
        'jquery.ui.touch-punch.min': ['jquery'],
        'bootstrap.min': ['jquery'],
        'SmartNotification.min': ['jquery'],
        'jarvis.widget.min': ['jquery'],
        'jquery.easy-pie-chart.min': ['jquery'],
        'jquery.sparkline.min': ['jquery'],
        "jquery.validate.min": ['jquery'],
        'jquery.maskedinput.min': ['jquery'],
        'select2.min': ['jquery'],
        'bootstrap-slider.min': ['jquery'],
        'jquery.mb.browser.min': ['jquery'],
        'fastclick.min': ['jquery'],
        'jquery.cookie': ['jquery'],
        'demo': ['jquery'],
        'sockjs.min': ['jquery'],
        'stomp.min': ['jquery'],
        'app': ['jquery', 'app.config', 'jquery-touch/jquery.ui.touch-punch.min',
            'bootstrap/bootstrap.min', 'notification/SmartNotification.min', 'smartwidgets/jarvis.widget.min',
            'easy-pie-chart/jquery.easy-pie-chart.min',
            'sparkline/jquery.sparkline.min', 'jquery-validate/jquery.validate.min',
            'masked-input/jquery.maskedinput.min',
            'select2/select2.min', 'bootstrap-slider/bootstrap-slider.min', 'msie-fix/jquery.mb.browser.min',
            'fastclick/fastclick.min', 'i18n/jquery.i18n.properties', 'jquery-cookie/jquery.cookie', 'demo',
            // 'sockjs/sockjs.min',
            'sockjs',
            'stomp/stomp.min'],
        "jquery.mockjax.min": ['jquery'],
        "x-editable.min": ['jquery'],
        'typeaheadjs.min': ['jquery', 'x-editable/x-editable.min'],
        'typeahead.min': ['jquery', 'x-editable/x-editable.min'],
        'datetimepicker': ['jquery'],
        'd3-main': ['jquery'],
        'd3.tip': ['jquery', 'd3/d3-main'],
        'wizard.min': ['jquery']
    }
})
;

require(['jquery', 'app', 'app.config', 'appLocalStorage', 'core/headBiz', 'model/global',
        'appConst', 'business/searchbar/searchbarBiz', 'business/socket/socketBiz', 'appMessageBox',
        'jquery.dataTables.min', 'dataTables.colVis.min', 'dataTables.tableTools.min',
        'dataTables.bootstrap.min','dataTables.responsive.min'], function ($, app, _, appLocalStorage, headBiz, global, appConst, searchbar, socketBiz, msgBox) {
        var userId = global.getUserId();

        $("#nav_global_project").click(function () {
            appLocalStorage.clearLocal("ispc.create.project.code." + userId);
            appLocalStorage.clearLocal("ispc.create.project.name." + userId);
            appLocalStorage.clearLocal("ispc.search.project.code." + userId);
            appLocalStorage.clearLocal("ispc.search.project.name." + userId);
            appLocalStorage.clearLocal("DataTables_dt_projects_/ispc/");
        });

        $("#nav_role").click(function () {
            appLocalStorage.clearLocal(appConst.searchKey.search_role_key + userId);
            appLocalStorage.clearLocal("DataTables_dt_roles_/ispc/");
        });

        $("#nav_user").click(function () {
            appLocalStorage.clearLocal(appConst.searchKey.search_user_key + userId);
            appLocalStorage.clearLocal("DataTables_dt_users_/ispc/");
        });

        $("#nav_group").click(function () {
            appLocalStorage.clearLocal(appConst.searchKey.search_group_key + userId);
            appLocalStorage.clearLocal("DataTables_dt_group_list_/ispc/");
        });

        $.ajaxSetup({
            timeout: appConst.ajax.timeout,
            complete: function (XMLHttpRequest, status) {
                if (status == 'timeout') {
                    msgBox.serverTimeoutBox();
                }
            }
        });

        headBiz.initTopMenuBar();

        socketBiz.initExport();


    }
);
